﻿using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DataLayer.SQL;
using System.Data;
using DataLayer.Manager;

namespace DataLayer.Providers
{
    public class UserProvider
    {
        DataAccess access;
        UserCmdManager manager;
        public UserProvider() {
            access = new DataAccess();
            manager = new UserCmdManager();
        }
        /// <summary>
        /// Obtiene una lista de todos los usuarios
        /// </summary>
        /// <returns>Lista que contiene todos los usuarios</returns>
        public List<UserInfo> GetAllUsers() {
            List<UserInfo> usersList = new List<UserInfo>();
            UserInfo user = null;
            DataRowCollection rows = access.GetDataTable(manager.GetAllUsersCommand()).Rows;
            foreach (DataRow row in rows)
            {
                user = new UserInfo();
                user.ID = Convert.ToInt32(row["Id"]);
                user.Active = Convert.ToBoolean(row["Active"]);
                user.UserName = row["UserName"].ToString();
                user.FirstName = row["FirstName"].ToString();
                user.LastName = row["Lastname"].ToString();
                usersList.Add(user);
            }
            return usersList;
        }
    }
}
